let Draw = agcim.interactive.draw;
let AgLabel = agcim.geometry.Label;
let AgBillboard = agcim.geometry.Billboard;
let AgPoint = agcim.geometry.Point;
let AgFeatureLayer = agcim.layer.FeatureLayer;

import picture from "../img/background.png";

var agFeatureLayer;

class HeightMeasure {
  constructor() {
    this.viewer = null;
    this.draw = null;
    agFeatureLayer = new AgFeatureLayer(CIM.viewer);
  }
  /**
   * @description: 初始化
   * @param {*} viewer 
   * @param {*} vm 
   */
  initialize(viewer, vm) {
    var _this = this;
    _this.viewer = viewer;
    _this.draw = new Draw(viewer);
    _this.draw
      .drawPoint({
        show: false,
      })
      .then((obj) => {
        if (agFeatureLayer._entities.length > 0) { agFeatureLayer.removeAll(); }
        var positions = obj.positions;
        var cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
        var height = cartographic.height.toFixed(1);
        vm.height = height;

        var labelOpt = {
          font: "16px Helvetica",
          pixelOffset: new Cesium.Cartesian2(25, -37),
        };
        var label = new AgLabel(
          "agLabel",
          positions[0],
          height + " m",
          labelOpt
        );
        label.addToLayer(agFeatureLayer);
        var billboardOpt = {
          width: 85,
          height: 25,
          disableDepthTestDistance: Number.POSITIVE_INFINITY,
          pixelOffset: new Cesium.Cartesian2(25, -25),
        };
        var billboard2 = new AgBillboard(
          "agBillboard",
          positions[0],
          picture,
          billboardOpt
        );
        billboard2.addToLayer(agFeatureLayer);
        var pointOpt = {
          color:Cesium.Color.CRIMSON,
          pixelSize:6,
          outlineColor:Cesium.Color.WHITE,
          ouelineWith:2
        };
        var point = new AgPoint(
          "agPoint",
          positions[0],
          pointOpt
        );
        point.addToLayer(agFeatureLayer);
        _this.initialize(viewer, vm);

      });
  }
  /**
   * 销毁
   */
  dispose() {
    agFeatureLayer.removeAll();
    this.draw.dispose();
  }
}

export default new HeightMeasure();
